// models/user.js
const db = require('../../db/db');

function getUserById(userId) {
    return new Promise((resolve, reject) => {
        db.get('SELECT * FROM users WHERE id = ?', [userId], (err, row) => {
            if (err) reject(err);
            else resolve(row);
        });
    });
}

function getUserByLoginName(loginName) {
    return new Promise((resolve, reject) => {
        db.get('SELECT * FROM users WHERE login_name = ?', [loginName], (err, row) => {
            if (err) reject(err);
            else resolve(row);
        });
    });
}

function createUser(loginName, password) {
    return new Promise((resolve, reject) => {
        db.run('INSERT INTO users (login_name, password) VALUES (?, ?)', [loginName, password], function (err) {
            if (err) reject(err);
            else resolve(this.lastID);
        });
    });
}

module.exports = {
    getUserById,
    getUserByLoginName,
    createUser
};